'use strict';

module.exports = clientType => async (ctx, next) => {
  const platId = ctx.get('yc-plat-id');
  if (platId) {
    ctx.locals.clientType = platId;
    if (clientType && ctx.locals.clientType !== clientType) {
      ctx.throw(ctx.HttpStatus.BAD_REQUEST, {
        code: -4001,
        message: '非指定客户端',
      });
    }
  } else {
    ctx.throw(ctx.HttpStatus.BAD_REQUEST, {
      code: -4001,
      message: '非指定客户端',
    });
  }
  await next();
};
